package com.dunglv.flashlight;

import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;

/**
 * Thread support older device
 * 
 * @author Dung
 * 
 */
class FlashThread extends Thread {
	// Must be volatile:
	private volatile boolean start = false;
	private Camera camera;

	public FlashThread(Camera camera) {
		this.camera = camera;
	}

	public void run() {
		while (!start) {
			try {
				System.out.println("alive");
				camera.autoFocus(new AutoFocusCallback() {
					public void onAutoFocus(boolean success, Camera camera) {
					}
				});
				Thread.sleep(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		if (start)
			System.out.println("Detected stop");
	}

	public synchronized void requestStop() {
		start = true;
	}
}